package dao;

import utils.JdbcUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 *
 */

public class UserDaoImpl implements UserDao {
    //修改当前用户密码
    @Override
    public int updata(Connection connection, int id, String password) throws SQLException {

        PreparedStatement preparedStatement = null;
        int i = 0;
        if (connection !=null){
            String sql = "update user_1 set password=?  where id =?";
            Object params[] = {password,id};
            i = BaseDao.execute(connection,sql,params,preparedStatement);
        }

        return i;
    }

    @Override
    public boolean updatePwd(int id, String password) {
        boolean flag = false;
        JdbcUtil jdbcUtil = new JdbcUtil();
        Connection connection = jdbcUtil.getConnection();
        try {
            if (updata(connection,id,password) > 0){
                flag = true;
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return false;
    }
}
